<template>
  <el-card style="height: 99%;padding: 0px">
    <p style="margin-left: 10px">首页>推荐字典管理</p>
    <el-button type="primary" @click="dialogFormVisible=true;addForm={}">添加推荐字典</el-button>
    <el-table
        :data="tableData"
        border
        style="width: 100%;line-height: 50px;margin-top: 10px;margin-bottom: 10px">
      <el-table-column
          prop="id"
          label="id"
      width="50">
      </el-table-column>
      <el-table-column
          prop="typeName"
          label="推荐类型名"
      >
      </el-table-column>
      <el-table-column
          prop="typeCode"
          label="推荐类型Code">
      </el-table-column>
      <el-table-column
          prop="valueName"
          label="推荐类别名">
      </el-table-column>
      <el-table-column
          prop="value"
          label="推荐描述">
      </el-table-column>
      <el-table-column>
        <template slot-scope="scope">
          <el-button
              size="mini"
              @click="handelDelete(scope.row.id)" type="danger">删除推荐字典</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
        background
        layout="prev, pager, next"
        :total="pageInfo.total"
        :page-size="pageInfo.pageSize"
        @current-change="handleCurrentChange">
    </el-pagination>
<!--    添加弹窗-->
    <el-dialog title="添加推荐字典" :visible.sync="dialogFormVisible">
      <el-form v-model="addForm">
        <el-form-item label="推荐字典名称" >
          <el-input v-model="addForm.typeName" ></el-input>
        </el-form-item>
        <el-form-item label="推荐字典Code" >
          <el-input v-model="addForm.typeCode"></el-input>
        </el-form-item>
        <el-form-item label="推荐类别名称">
          <el-input v-model="addForm.valueName"></el-input>
        </el-form-item>
        <el-form-item label="推荐类别描述" >
          <el-input v-model="addForm.value"></el-input>
        </el-form-item>
        <el-form-item label="推荐优先级">
          <el-input v-model="addForm.top"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取 消</el-button>
        <el-button type="primary" @click="addDic">确 定</el-button>
      </div>
    </el-dialog>
  </el-card>
</template>

<script>
import {doAddDic, doDeleteDic, doGetDictionarys} from "@/api/dic";

export default {
  name: "dicInfo",
  data() {
    return {
      tableData:[
      ],
      pageInfo:{
        total:1,
        pageNum:1,
        pageSize:8
      },
      dialogFormVisible:false,
      addForm:{
        typeName:'',
        typeCode:'',
        valueName:'',
        value:'',
        top:10,
      }
    }
  },methods: {
    getDic(){
          doGetDictionarys(this.pageInfo.pageNum,this.pageInfo.pageSize).then(res=>{
              if (res.code===200){
                  this.pageInfo.total=res.data.total;
                  this.tableData=res.data.records;
              }
          })
      },
      handleCurrentChange(val) {
        this.pageInfo.pageNum=val;
        this.getDic();
      },
      addDic(){
        doAddDic(this.addForm).then(res=>{
          if (res.code===200){
            this.dialogFormVisible=false;
            this.getDic();
          }
        })
      },
    handelDelete(id){
      doDeleteDic(id).then(res=>{
        if (res.code===200){
          this.getDic();
        }
      })
    }
  },
  mounted() {
    this.getDic();
  }
}
</script>

<style lang="less" scoped>

</style>